﻿using FixtureManageSystem.ControlWidget;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;

using FixtureManageSystem.Views;
using OfficeOpenXml.ConditionalFormatting;
using System.Collections.Generic;

namespace FixtureManageSystem
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private Dictionary<string, ClosableTab> Header2ClosableTab;
        public MainWindow()
        {
            InitializeComponent();
            Header2ClosableTab = new Dictionary<string, ClosableTab>();
        }

        private void TreeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TreeView trv = sender as TreeView;
            TreeViewItem tvm = trv.SelectedItem as TreeViewItem;
            if (tvm == null)
            { return; }
            string header = tvm.Header.ToString();
            //((TabControl)this.Parent).Items.Remove(this);
            if (Header2ClosableTab.ContainsKey(header))
            {
                ClosableTab tab = Header2ClosableTab[header];
                if ((TabControl)tab.Parent == null)
                {
                    MainPanel.Items.Add(tab);
                }
                tab.Focus();
                return;
            }
            ClosableTab ctab = new ClosableTab();
            ctab.Title = header;

            // 根据header 选择content page
            Page contentPage;
            Frame tabFrame = new Frame();
            
            switch (header)
            {
                case "员工管理":
                    contentPage = new Employee();
                    break;
                case "借用归还":
                    contentPage = new BorrowReturn();
                    break;
                case "辅料入库":
                    contentPage = new WareHouseIn();
                    break;
                case "数据统计":
                    contentPage = new Ledger();
                    break;
                case "数据导出":
                    contentPage = new DataExport();
                    break;
                default:
                    contentPage = new Page();
                    break;
            }
            tabFrame.Content = contentPage;
            ctab.Content = tabFrame; 
            MainPanel.Items.Add(ctab);
            MainPanel.SelectedIndex = MainPanel.Items.Count - 1;
            ctab.Focus();
            Header2ClosableTab[header] = ctab;
        }

    }
}
